package com.ymatou.iapi.im.testcase;

import com.ymatou.iapi.im.parameter.CommentDto;
import com.ymatou.iapi.im.parameter.GetCommentListByTimelineBean;
import com.ymatou.iapi.im.parameter.SendCommentBean;
import com.ymatou.iapi.im.service.GetCommentListByTimelineCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ImCallService;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import com.ymttest.utils.YMTDateUtil;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.List;
import java.util.Map;

/**
*根据时间获取评论列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetCommentListByTimeline{
	private static GetCommentListByTimelineBean getcommentlistbytimelineBean;
	private static GetCommentListByTimelineCall getcommentlistbytimelineCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据时间获取评论列表");
	}

	@Before
	public void caseUp() {
		getcommentlistbytimelineBean=new GetCommentListByTimelineBean();
		getcommentlistbytimelineCall=new GetCommentListByTimelineCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getcommentlistbytimelineCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCommentListByTimeline_001() {
		Logger.start(true,"根据时间获取评论列表,历史消息");
		try {
			ImCallService imCallService = new ImCallService();
			SendCommentBean sendCommentBean = imCallService.initSendComment();
			imCallService.SendComment(sendCommentBean);
			int count = 5;
			getcommentlistbytimelineBean.setCount(count);
			Long longTimeLine = YMTDateUtil.getDate().getTime()-36000;
			getcommentlistbytimelineBean.setLongTimeline(longTimeLine);
			getcommentlistbytimelineBean.setIsNew("No");
			getcommentlistbytimelineBean.setUserId(sendCommentBean.getToUserId());
			getcommentlistbytimelineCall.setData(getcommentlistbytimelineBean);
			getcommentlistbytimelineCall.callService();
			Logger.verifyEquals("200",getcommentlistbytimelineCall.getString("Status"),"验证Status");
			ImDefaultWapper im =  new ImDefaultWapper();
			List<Map> list = im.selectCommentByTime(sendCommentBean.getToUserId(),longTimeLine,count,"No");
			List<CommentDto> CommentDtoList = getcommentlistbytimelineCall.getCommentDtoList();
			for(int i = 0;i < CommentDtoList.size();i++){
				Logger.verifyEquals(CommentDtoList.get(i).getMessage(),list.get(i).get("Message").toString(),"验证Message");
				if (list.get(i).get("ObjLogo")!=null){
					Logger.verifyEquals(CommentDtoList.get(i).getObjLogo(),list.get(i).get("ObjLogo").toString(),"ObjLogo");
				}
				Logger.verifyEquals(CommentDtoList.get(i).getObjId(),list.get(i).get("ObjId").toString(),"ObjId");
				Logger.verifyEquals(CommentDtoList.get(i).getObjType(),Integer.parseInt(list.get(i).get("ObjType").toString()),"ObjType");
				Logger.verifyEquals(CommentDtoList.get(i).getUnReadCount(),Integer.parseInt(list.get(i).get("UnReadCount").toString()),"UnReadCount");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCommentListByTimeline_002() {
		Logger.start(true,"根据时间获取评论列表,新消息");
		try {
			ImCallService imCallService = new ImCallService();
			SendCommentBean sendCommentBean = imCallService.initSendComment();
			imCallService.SendComment(sendCommentBean);
			int count = 5;
			getcommentlistbytimelineBean.setCount(count);
			Long longTimeLine = YMTDateUtil.getDate().getTime()-3600000;
			getcommentlistbytimelineBean.setLongTimeline(longTimeLine);
			getcommentlistbytimelineBean.setIsNew("Yes");
			getcommentlistbytimelineBean.setUserId(sendCommentBean.getToUserId());
			getcommentlistbytimelineCall.setData(getcommentlistbytimelineBean);
			getcommentlistbytimelineCall.callService();
			Logger.verifyEquals("200",getcommentlistbytimelineCall.getString("Status"),"验证Status");
			ImDefaultWapper im =  new ImDefaultWapper();
			List<Map> list = im.selectCommentByTime(sendCommentBean.getToUserId(),longTimeLine,count,"Yes");
			List<CommentDto> CommentDtoList = getcommentlistbytimelineCall.getCommentDtoList();
			System.out.println(CommentDtoList);
			for(int i =0;i <CommentDtoList.size(); i++){
				Logger.verifyEquals(CommentDtoList.get(i).getMessage(),list.get(i).get("Message").toString(),"验证Message");
				Logger.verifyEquals(CommentDtoList.get(i).getObjLogo(),list.get(i).get("ObjLogo").toString(),"ObjLogo");
				Logger.verifyEquals(CommentDtoList.get(i).getObjId(),list.get(i).get("ObjId").toString(),"ObjId");
				Logger.verifyEquals(CommentDtoList.get(i).getObjType(),Integer.parseInt(list.get(i).get("ObjType").toString()),"ObjType");
				Logger.verifyEquals(CommentDtoList.get(i).getUnReadCount(),Integer.parseInt(list.get(i).get("UnReadCount").toString()),"UnReadCount");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


}